import axios, {AxiosResponse} from "axios";

import DictionaryModel from "@/models/DictionaryModel";
import {BackendPageModel} from "@/models/BackendPageModel";

export function getAllDict(): Promise<DictionaryModel[]> {
    return new Promise((resolve, reject) => {
        axios({method: 'get', url: `/api/dict/all`}).then((value: AxiosResponse<DictionaryModel[]>) => {
            console.log()
            resolve(value.data);
        }).catch(reason => {
            reject();
        })
    })
}

export function getDict(pageNo = 0, pageSize = 10): Promise<BackendPageModel<DictionaryModel>> {
    return new Promise((resolve, reject) => {
        axios({method: 'get', url: '/api/dict/page', data: {pageSize: pageSize, PageNumber: pageNo}}).then(value => {
            resolve(value.data);
        }).catch(reason => {
            reject();
        })
    })
}

export function createDictType(typeCode: string, typeName: string): Promise<boolean> {
    return new Promise((resolve, reject) => {
        axios({method: 'post', url: '/api/dict/type', data: {typeCode: typeCode, typeName: typeName}}).then(value => {
            resolve(value.data);
        }).catch(reason => {
            reject();
        })
    })
}